unit unitadminpuesto;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  unitpuesto, unitmainform;

type

  { TFormAdminPuesto }

  TFormAdminPuesto = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  FormAdminPuesto: TFormAdminPuesto;

implementation

{$R *.lfm}

{ TFormAdminPuesto }

procedure TFormAdminPuesto.Button2Click(Sender: TObject);
begin
  Close();
end;

procedure TFormAdminPuesto.FormClose(Sender: TObject;
  var CloseAction: TCloseAction);
begin
  label3.Caption := '';
  Edit1.Text := '';
  Edit2.Text := '';
end;

procedure TFormAdminPuesto.Button1Click(Sender: TObject);
var
  QueryString: string;

begin
  if Button1.Caption = 'Guardar' then
    QueryString := 'insert into puesto(pst_nombre, pst_descripcion) values(''' + Edit1.Text + ''', ''' + Edit2.Text + ''')'
  else
  if Button1.Caption = 'Actualizar' then
    QueryString := 'update puesto set pst_nombre = ''' + Edit1.text + ''', pst_descripcion = ''' + Edit2.Text
      + ''' where pst_cdg = ' + Label3.Caption;

  MainForm.PQConnection1.ExecuteDirect('BEGIN WORK;');
  MainForm.PQConnection1.ExecuteDirect(QueryString);
  MainForm.PQConnection1.ExecuteDirect('COMMIT WORK;');

  ShowMessage('Operación Exitosa!');
  Close();
end;

end.

